﻿Imports System.Data
Imports ADOEntityKYC
Partial Class NonIndividualBoardNon
    Inherits Web.UI.BasePage

#Region " Variable Gobal "

    Dim ds As DataSet
    Dim clsRiskLevel As clsRiskLevel = New clsRiskLevel
    Dim clsDatabase As clsDatabase
    Dim KYCEntity As KYCEntities = New KYCEntities
    Dim clsSessionMenuRight As clsSessionMenuRight = New clsSessionMenuRight
    Dim TypeKYC As Integer = 0
    Dim CustSeq As Integer = 0
    Dim clsCheckLanguage As clsCheckLanguage
    Dim clsCheckID As clsCheckID
    Dim strMsg As String = ""
    Dim index As Integer = -1

#End Region

#Region "Even Page"

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            btnSearch.Attributes.Add("onclick", "NoDoubleSubmit();")
            'btnCompile.Attributes.Add("onclick", "NoDoubleSubmitCompile();")
            btnCompile.Attributes.Add("onClick", "NoDoubleSubmitCompile(); myDialog();")

            ds = Session("ds")
            index = Request.QueryString("index")
            TypeKYC = Request.QueryString("TypeKYC")
            CustSeq = Request.QueryString("CUSTSEQ")

            clsSessionMenuRight = Session("clsMenuRight")

            If Not TypeKYC = 4 Then
                btnCancel.Attributes.Add("onclick", "return confirm('" + String.Format(Resources.resMsgKYC.msgCancle) + "')")
            End If

            If Not IsPostBack Then
                chkIsLogin()
                loadDataToDropDown()
                CreateControlMP()

                lblCustSEQ.Text = Request.QueryString("CUSTSEQ")
                lblTypeKYC.Text = Request.QueryString("TypeKYC")

                hdfID.Value = Request.QueryString("UNIQUEID")

                If index > -1 Then 'แก้ไขข้อมูล
                    BindingData()
                    indexBizChanging1()
                    indexBizChanging2()
                    indexBizChanging3()
                    Session("CustSeqBoard") = CustSeq

                    If Not ds.Tables("dsCustomerCom").Rows(index)("CreateBy") Is DBNull.Value Then
                        If Not ds.Tables("dsCustomerCom").Rows(index)("CreateBy") = "AutoGenPK" Then
                            btnHistory.Visible = False
                        Else
                            btnHistory.Visible = True
                        End If
                    Else
                        btnHistory.Visible = True
                    End If

                Else
                    PanelCust.Enabled = False
                    btnHistory.Visible = False
                End If

                If TypeKYC = 4 Then
                    'compileCDD()
                    txtRiskLevel.Text = "ลูกค้ามีความเสี่ยงระดับ " + CStr(ds.Tables("dsCustomerCom").Rows(index)("AMLCDD"))
                    txtReason.Text = ds.Tables("dsCustomerCom").Rows(index)("AMLREASON").ToString

                    Panel1.Enabled = False
                    btnCancel.Text = "ปิด"
                    'btnSave.Visible = False
                End If

            End If
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
        Session("ds") = ds
    End Sub

#End Region

#Region "SetForm"

    Sub CreateControlMP()
        Dim img As Image = CType(Master.FindControl("imgHead"), Image)
        img.ImageUrl = "~/img/LogoNonIndi.jpg"

        Dim page As Label = CType(Master.FindControl("lblPage"), Label)
        page.Text = "ประเมินความเสี่ยง ผู้ถือหุ้น"
    End Sub

#End Region

#Region "Event Dropdrown"

    Protected Sub ddlBusiness1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlBusiness1.SelectedIndexChanged
        indexBizChanging1()
    End Sub


    Protected Sub ddlBusiness2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlBusiness2.SelectedIndexChanged
        indexBizChanging2()
    End Sub

    Protected Sub ddlBusiness3_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlBusiness3.SelectedIndexChanged
        indexBizChanging3()
    End Sub

    Protected Sub ddlBizType_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlBizType.SelectedIndexChanged
        UpdatePanel9.Update()
        autoBizType()
    End Sub
#End Region

#Region "Event Button"

    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Try
            FindCustomer()
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClear.Click
        Try
            lblMsg.Visible = False

            lblCustSEQ.Text = 0

            txtBizNo.Text = ""
            ddlBizType.SelectedValue = ""
            ddlPrefix.SelectedValue = ""
            txtNameTH.Text = ""
            txtNameEN.Text = ""
            ddlBusiness1.SelectedIndex = -1
            txtBizOther1.Text = ""
            ddlBusiness2.SelectedIndex = -1
            txtBizOther2.Text = ""
            ddlBusiness3.SelectedIndex = -1
            txtBizOther3.Text = ""
            txtDes1.Text = ""
            txtDes2.Text = ""
            txtDes3.Text = ""
            ddlIncomeSource2.SelectedIndex = -1
            ddlIncomeSource3.SelectedIndex = -1

            ddlPosition.SelectedIndex = -1
            ddlNationality.SelectedValue = 202
            ddlIncomeSource1.SelectedValue = 202

            lblCustCode.Text = "เลขประจำตัวลูกค้า : -"

            PanelCust.Enabled = False

            chkRegister.Items(0).Selected = False
            chkRegister.Items(1).Selected = False
            chkRegister.Items(2).Selected = False
            chkNGO.Items(0).Selected = False
            chkNGO.Items(1).Selected = False

            statusValidationFalse()
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btnCompile_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCompile.Click
        Try


            If Session("chkKYC") = True Then
                GoTo compile
            End If

            If checkBeforeCompile() = True Then
compile:
                If (Panel2.Enabled = True) Then

                    compileCDD()

                    Session("chkKYC") = Nothing
                    Panel2.Enabled = False
                    btnCompile.Visible = False
                    btnEditCompile.Visible = True
                    btnReport.Visible = True
                Else
                    Panel2.Enabled = True
                    btnCompile.Visible = True
                    btnEditCompile.Visible = False
                    btnReport.Visible = False

                End If
            Else

                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & strMsg & "')", True)

                'btnSave.Visible = False
                btnReport.Visible = False

                txtRiskLevel.Text = ""
                lblLevel.Text = 0
                txtReason.Text = ""
                txtRiskLevel.BackColor = Drawing.Color.White

            End If



        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btnHistory_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnHistory.Click
        Try
            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.open('CDDHistory.aspx?CUSTSEQ=" & CInt(CustSeq) & "&CUSTTYPE=2" & "','_blank','scrollbars=1,Width:800px, Height:600px')", True)
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Try
            If ddlPosition.SelectedIndex = 0 Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgAlertKYC.NotPosition & "')", True)
                Image10.ImageUrl = "~/img/icon/cancel.png"
                Image10.Visible = True
                Exit Sub
            End If

            If Not (hdfID.Value = txtBizNo.Text.Trim) Then
                If Not (chkCardIdDuplicate(txtBizNo.Text.Trim)) Then
                    strMsg = "เลขทะเบียนนิติบุคคล " + txtBizNo.Text + " ได้มีการกรอกข้อมูลผู้เกี่ยวข้องแล้ว "
                    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & strMsg & "')", True)
                    Exit Sub
                End If
            End If


            If index = -1 Then
                saveData()
            Else 'แก้ไขข้อมูล
                updateData()
            End If
            Session("strReason") = Nothing
            Session("ds") = ds
            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.close();", True)

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btnReport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReport.Click
        Try
            If ddlPosition.SelectedIndex = 0 Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgAlertKYC.NotPosition & "')", True)
                Image10.ImageUrl = "~/img/icon/cancel.png"
                Image10.Visible = True
                Exit Sub
            End If

            If Not (hdfID.Value = txtBizNo.Text.Trim) Then
                If Not (chkCardIdDuplicate(txtBizNo.Text.Trim)) Then
                    strMsg = "เลขทะเบียนนิติบุคคล " + txtBizNo.Text + " ได้มีการกรอกข้อมูลผู้เกี่ยวข้องแล้ว "
                    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & strMsg & "')", True)
                    Exit Sub
                End If
            End If

            'ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.showModalDialog('../Form/KYCResultBiz.aspx?uniqueID=" & txtBizNo.Text.Trim & "&" _
            '                                   & "BizType=" & ddlBizType.Text & "&" _
            '                                   & "PrefixTH=" & ddlPrefix.Text & "&" _
            '                                   & "NameTh1=" & txtNameTH.Text.Trim & "&" _
            '                                   & "NameEN1=" & txtNameEN.Text.Trim & "&" _
            '                                   & "Nationality=" & ddlNationality.Text & "&" _
            '                                   & "Business1=" & ddlBusiness1.Text & "&" _
            '                                   & "BizOther1=" & txtBizOther1.Text.Trim & "&" _
            '                                   & "Des1=" & txtDes1.Text.Trim & "&" _
            '                                   & "Business2=" & ddlBusiness2.Text & "&" _
            '                                   & "BizOther2=" & txtBizOther2.Text.Trim & "&" _
            '                                   & "Des2=" & txtDes2.Text.Trim & "&" _
            '                                   & "Business3=" & ddlBusiness3.Text & "&" _
            '                                   & "BizOther3=" & txtBizOther3.Text.Trim & "&" _
            '                                   & "Des3=" & txtDes3.Text.Trim & "&" _
            '                                   & "IncomeSource1=" & ddlIncomeSource1.Text & "&" _
            '                                   & "IncomeSource2=" & ddlIncomeSource2.Text & "&" _
            '                                   & "IncomeSource3=" & ddlIncomeSource3.Text & "&" _
            '                                   & "RiskLevel=" & txtRiskLevel.Text.Trim & "&" _
            '                                   & "Reason=" & txtReason.Text.Trim & "'" _
            '                                   & ", null, 'status:no; dialogWidth:1000px; dialogHeight:600px; help:no; scroll:yes; menubar:no; resizable:no')", True)

            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.showModalDialog('../Form/KYCResultBiz.aspx?uniqueID=" & txtBizNo.Text.Trim & "&" _
                                               & "BizType=" & ddlBizType.Text & "&" _
                                               & "PrefixTH=" & ddlPrefix.Text & "&" _
                                               & "NameTh1=" & txtNameTH.Text.Trim & "&" _
                                               & "NameEN1=" & txtNameEN.Text.Trim & "&" _
                                               & "Nationality=" & ddlNationality.Text & "&" _
                                               & "Business1=" & ddlBusiness1.Text & "&" _
                                               & "BizOther1=" & txtBizOther1.Text.Trim & "&" _
                                               & "Des1=" & txtDes1.Text.Trim & "&" _
                                               & "Business2=" & ddlBusiness2.Text & "&" _
                                               & "BizOther2=" & txtBizOther2.Text.Trim & "&" _
                                               & "Des2=" & txtDes2.Text.Trim & "&" _
                                               & "Business3=" & ddlBusiness3.Text & "&" _
                                               & "BizOther3=" & txtBizOther3.Text.Trim & "&" _
                                               & "Des3=" & txtDes3.Text.Trim & "&" _
                                               & "IncomeSource1=" & ddlIncomeSource1.Text & "&" _
                                               & "IncomeSource2=" & ddlIncomeSource2.Text & "&" _
                                               & "IncomeSource3=" & ddlIncomeSource3.Text & "&" _
                                               & "RiskLevel=" & txtRiskLevel.Text.Trim &  "'" _
                                               & ", null, 'status:no; dialogWidth:1000px; dialogHeight:600px; help:no; scroll:yes; menubar:no; resizable:no')", True)




            If index = -1 Then
                saveData()
            Else 'แก้ไขข้อมูล
                updateData()
            End If
            Session("strReason") = txtReason.Text
            Session("ds") = ds

            SaveLogPrint(2)
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btnKYC_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnKYC.Click

    End Sub

    Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Try
            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.close();", True)
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

#End Region

#Region "Function"

    Private Sub loadDataToDropDown()
        Try
            Dim clsDropDown As New clsMasterDropDown

            clsDropDown.setSubTypeToDdl(ddlBizType)
            clsDropDown.setPrefixTHToDdl(ddlPrefix, 2)
            clsDropDown.setNationalityToDdl(ddlNationality)
            clsDropDown.setBusinessToDdl(ddlBusiness1)
            clsDropDown.setBusinessToDdl(ddlBusiness2)
            clsDropDown.setBusinessToDdl(ddlBusiness3)
            clsDropDown.setCountyToDdl(ddlIncomeSource1)
            clsDropDown.setCountyToDdl(ddlIncomeSource2)
            clsDropDown.setCountyToDdl(ddlIncomeSource3)

            clsDropDown.setPositionToDdl(ddlPosition)

            ddlNationality.SelectedValue = 202
            ddlIncomeSource1.SelectedValue = 202


            clsDropDown = Nothing
        Catch ex As Exception
            WriteError(ex, "loadDataToDropDown", "NonIndividualBoardNon")
            Throw ex
        End Try
    End Sub

    Private Sub AutoInput()
        Try
            txtBizNo.Text = Request.QueryString("BIZCODE")
            txtNameTH.Text = Request.QueryString("NAMETH")
            txtNameEN.Text = Request.QueryString("NAMEEN")
        Catch ex As Exception
            WriteError(ex, "AutoInput", "NonIndividualBoardNon")
            Throw ex
        End Try
    End Sub

    Private Sub FindCustomer()
        Try
            clsCheckID = New clsCheckID
            If txtBizNo.Text.Trim = "" Then
                Image1.ImageUrl = "~/img/icon/cancel.png"
                Image1.Visible = True
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgAlertKYC.NotBizID & "')", True)

                'ElseIf Not txtBizNo.Text.Trim.Length = 13 Then
                '    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgAlertKYC.CheckBizNo & "')", True)

            Else

                'Dim qryCust = (From cust In KYCEntity.MCUSTOMER _
                '          Group Join r In KYCEntity.MCOMPRELATION On cust.CUSTSEQ Equals r.REFCUSTSEQ _
                '          Into ref = Group From leftjoinref In ref.DefaultIfEmpty _
                '          Where cust.UNIQUEID = txtBizNo.Text.Trim And Not cust.CUSTSUBTYPE = 1
                '          Select cust, leftjoinref.POCODE).ToList

                Dim qryCust = (From cust In KYCEntity.MCUSTOMER _
                       Where cust.UNIQUEID = txtBizNo.Text.Trim And cust.CUSTTYPE = 2
                       Select cust.CUSTSEQ, cust.CUSTCODE, cust.CUSTSUBTYPE,
                        cust.THPREFIX, cust.THFIRSTNAME,
                        cust.ENPREFIX, cust.ENFIRSTNAME,
                        cust.NATIONALITY, cust.BIZDESC1, cust.BIZDESC2, cust.BIZDESC3,
                         cust.BIZTYPE1, cust.BIZTYPE2, cust.BIZTYPE3,
                        cust.BIZTYPEOTHER1, cust.BIZTYPEOTHER2, cust.BIZTYPEOTHER3,
                        cust.INCOMESOURCE1, cust.INCOMESOURCE2, cust.INCOMESOURCE3,
                        cust.AMLCDDSAS, cust.AMLREASONSAS, cust.NGOCHECK1, cust.COMPCHECK1
                        ).ToList

                PanelCust.Enabled = True

                If qryCust.Count = 0 Then
                    lblMsg.Visible = True
                    lblCustSEQ.Text = 0
                    Session("CustSeqBoard") = 0
                    Session("TypeKYCBoard") = 1
                Else
                    lblMsg.Visible = False
                    'txtBizNo.Enabled = False

                    hdfUniqueID.Value = txtBizNo.Text
                    Session("TypeKYCBoard") = 2
                    Session("CustSeqBoard") = qryCust(0).CUSTSEQ
                    lblTypeKYC.Text = 2
                    lblCustSEQ.Text = qryCust(0).CUSTSEQ

                    ddlBizType.SelectedValue = qryCust(0).CUSTSUBTYPE
                    ddlPrefix.SelectedValue = qryCust(0).THPREFIX
                    txtNameTH.Text = qryCust(0).THFIRSTNAME
                    txtNameEN.Text = qryCust(0).ENFIRSTNAME
                    If Not qryCust(0).NATIONALITY Is Nothing Then
                        ddlNationality.SelectedValue = qryCust(0).NATIONALITY
                    End If
                    If Not qryCust(0).BIZTYPE1 Is Nothing Then
                        ddlBusiness1.SelectedValue = qryCust(0).BIZTYPE1
                    End If
                    txtBizOther1.Text = qryCust(0).BIZTYPEOTHER1
                    If Not qryCust(0).BIZTYPE2 Is Nothing Then
                        ddlBusiness2.SelectedValue = qryCust(0).BIZTYPE2
                    End If
                    txtBizOther2.Text = qryCust(0).BIZTYPEOTHER2
                    If Not qryCust(0).BIZTYPE3 Is Nothing Then
                        ddlBusiness3.SelectedValue = qryCust(0).BIZTYPE3
                    End If
                    txtBizOther3.Text = qryCust(0).BIZTYPEOTHER3

                    txtDes1.Text = qryCust(0).BIZDESC1
                    txtDes2.Text = qryCust(0).BIZDESC2
                    txtDes3.Text = qryCust(0).BIZDESC3

                    If Not qryCust(0).INCOMESOURCE1 Is Nothing Then
                        ddlIncomeSource1.SelectedValue = qryCust(0).INCOMESOURCE1
                    End If
                    If Not qryCust(0).INCOMESOURCE2 Is Nothing Then
                        ddlIncomeSource2.SelectedValue = qryCust(0).INCOMESOURCE2
                    End If
                    If Not qryCust(0).INCOMESOURCE3 Is Nothing Then
                        ddlIncomeSource3.SelectedValue = qryCust(0).INCOMESOURCE3
                    End If

                    'If Not qryCust(0).POCODE Is Nothing Then
                    '    ddlPosition.SelectedValue = qryCust(0).POCODE
                    'End If

                    If Not qryCust(0).NGOCHECK1 Is Nothing Then
                        If qryCust(0).NGOCHECK1 = 1 Then
                            chkNGO.Items(0).Selected = True
                        ElseIf qryCust(0).NGOCHECK1 = 2 Then
                            chkNGO.Items(1).Selected = True
                        End If
                    End If

                    If Not qryCust(0).COMPCHECK1 Is Nothing Then
                        If qryCust(0).COMPCHECK1 = 1 Then
                            chkRegister.Items(0).Selected = True
                        ElseIf qryCust(0).COMPCHECK1 = 2 Then
                            chkRegister.Items(1).Selected = True
                        ElseIf qryCust(0).COMPCHECK1 = 3 Then
                            chkRegister.Items(2).Selected = True
                        End If
                    End If


                    lblCustCode.Text = "เลขประจำตัวลูกค้า : " & qryCust(0).CUSTCODE

                    txtReasonSAS.Text = qryCust(0).AMLREASONSAS
                    hdfAML.Value = qryCust(0).AMLCDDSAS.ToString

                    autoBizType()

                    'Else
                    '    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgKYC.msgCheckID & "')", True)
                End If

            End If

            clsCheckID = Nothing
        Catch ex As Exception
            WriteError(ex, "FindCustomer", "NonIndividualBoardNon")
            Throw ex
        End Try
    End Sub

    Sub BindingData()
        Try
            txtBizNo.Text = ds.Tables("dsCustomerCom").Rows(index)("UniqueID")
            hdfUniqueID.Value = ds.Tables("dsCustomerCom").Rows(index)("UniqueID")
            ddlBizType.SelectedValue = ds.Tables("dsCustomerCom").Rows(index)("CUSTSUBTYPE")
            ddlPrefix.SelectedValue = ds.Tables("dsCustomerCom").Rows(index)("ThPreFix").ToString
            txtNameTH.Text = ds.Tables("dsCustomerCom").Rows(index)("ThFirstName")
            txtNameEN.Text = ds.Tables("dsCustomerCom").Rows(index)("EnFirstName").ToString
            ddlNationality.SelectedValue = ds.Tables("dsCustomerCom").Rows(index)("Nationality")
            If Not ds.Tables("dsCustomerCom").Rows(index)("BIZTYPE1") Is DBNull.Value Then
                ddlBusiness1.SelectedValue = ds.Tables("dsCustomerCom").Rows(index)("BIZTYPE1")
            End If
            txtBizOther1.Text = ds.Tables("dsCustomerCom").Rows(index)("BIZTYPEOTHER1").ToString
            If Not ds.Tables("dsCustomerCom").Rows(index)("BIZTYPE2") Is DBNull.Value Then
                ddlBusiness2.SelectedValue = ds.Tables("dsCustomerCom").Rows(index)("BIZTYPE2")
            End If
            txtBizOther2.Text = ds.Tables("dsCustomerCom").Rows(index)("BIZTYPEOTHER2").ToString
            If Not ds.Tables("dsCustomerCom").Rows(index)("BIZTYPE3") Is DBNull.Value Then
                ddlBusiness3.SelectedValue = ds.Tables("dsCustomerCom").Rows(index)("BIZTYPE3")
            End If
            txtBizOther3.Text = ds.Tables("dsCustomerCom").Rows(index)("BIZTYPEOTHER3").ToString

            txtDes1.Text = ds.Tables("dsCustomerCom").Rows(index)("BIZDESC1").ToString
            txtDes2.Text = ds.Tables("dsCustomerCom").Rows(index)("BIZDESC2").ToString
            txtDes3.Text = ds.Tables("dsCustomerCom").Rows(index)("BIZDESC3").ToString

            ddlIncomeSource1.SelectedValue = ds.Tables("dsCustomerCom").Rows(index)("IncomeSource1")
            If Not ds.Tables("dsCustomerCom").Rows(index)("IncomeSource2") Is DBNull.Value Then
                ddlIncomeSource2.SelectedValue = ds.Tables("dsCustomerCom").Rows(index)("IncomeSource2")
            End If
            If Not ds.Tables("dsCustomerCom").Rows(index)("IncomeSource3") Is DBNull.Value Then
                ddlIncomeSource3.SelectedValue = ds.Tables("dsCustomerCom").Rows(index)("IncomeSource3")
            End If

            ddlPosition.SelectedValue = ds.Tables("dsCustomerCom").Rows(index)("Pocode")

            autoBizType()

            If Not ds.Tables("dsCustomerCom").Rows(index)("NGOCHECK1") Is DBNull.Value Then
                If ds.Tables("dsCustomerCom").Rows(index)("NGOCHECK1") = 1 Then
                    chkNGO.Items(0).Selected = True
                ElseIf ds.Tables("dsCustomerCom").Rows(index)("NGOCHECK1") = 2 Then
                    chkNGO.Items(1).Selected = True
                End If
            End If

            If Not ds.Tables("dsCustomerCom").Rows(index)("COMPCHECK1") Is DBNull.Value Then
                If ds.Tables("dsCustomerCom").Rows(index)("COMPCHECK1") = 1 Then
                    chkRegister.Items(0).Selected = True
                ElseIf ds.Tables("dsCustomerCom").Rows(index)("COMPCHECK1") = 2 Then
                    chkRegister.Items(1).Selected = True
                ElseIf ds.Tables("dsCustomerCom").Rows(index)("COMPCHECK1") = 3 Then
                    chkRegister.Items(2).Selected = True
                End If
            End If


            lblRiskNow.Text = "ความเสี่ยงล่าสุด : " + CStr(ds.Tables("dsCustomerCom").Rows(index)("AMLCDD"))
            lblRiskNow.Visible = True

            If ds.Tables("dsCustomerCom").Rows(index)("AMLCDD") = 1 Then
                lblRiskNow.ForeColor = Drawing.Color.Green
            ElseIf ds.Tables("dsCustomerCom").Rows(index)("AMLCDD") = 2 Then
                lblRiskNow.ForeColor = Drawing.Color.Orange
            ElseIf ds.Tables("dsCustomerCom").Rows(index)("AMLCDD") = 3 Then
                lblRiskNow.ForeColor = Drawing.Color.Red
            End If
            If Not ds.Tables("dsCustomerCom").Rows(index)("AMLREASONSAS") Is DBNull.Value Then
                txtReasonSAS.Text = ds.Tables("dsCustomerCom").Rows(index)("AMLREASONSAS")
            End If
            If Not ds.Tables("dsCustomerCom").Rows(index)("AMLCDDSAS") Is DBNull.Value Then
                hdfAML.Value = ds.Tables("dsCustomerCom").Rows(index)("AMLCDDSAS")
            End If
        Catch ex As Exception
            WriteError(ex, "Bindingdata", "NonIndividualBoardNon")
            Throw ex
        End Try
    End Sub

#Region "Function Drop Drown"

    Private Sub indexBizChanging1()
        If Not ddlBusiness1.SelectedValue = "" Then
            If ddlBusiness1.SelectedValue = 99 Then
                txtBizOther1.Visible = True
                lblOther12.Visible = True
            Else
                txtBizOther1.Visible = False
                txtBizOther1.Text = ""
                lblOther12.Visible = False
            End If
        Else
            txtBizOther1.Visible = False
            txtBizOther1.Text = ""
            lblOther12.Visible = False
        End If
    End Sub

    Private Sub indexBizChanging2()
        If Not ddlBusiness2.SelectedValue = "" Then
            If ddlBusiness2.SelectedValue = 99 Then
                txtBizOther2.Visible = True
                lblOther22.Visible = True
            Else
                txtBizOther2.Visible = False
                txtBizOther2.Text = ""
                lblOther22.Visible = False
            End If
        Else
            txtBizOther2.Visible = False
            txtBizOther2.Text = ""
            lblOther22.Visible = False
        End If

    End Sub

    Private Sub indexBizChanging3()

        If Not ddlBusiness3.SelectedValue = "" Then
            If ddlBusiness3.SelectedValue = 99 Then
                txtBizOther3.Visible = True
                lblOther32.Visible = True
            Else
                txtBizOther3.Visible = False
                txtBizOther3.Text = ""
                lblOther32.Visible = False
            End If
        Else
            txtBizOther3.Visible = False
            txtBizOther3.Text = ""
            lblOther32.Visible = False
        End If

    End Sub

    Private Sub autoBizType()
        If ddlBizType.SelectedValue = 3 Then
            chkNGO.Enabled = True
            chkRegister.Enabled = False
            chkRegister.Items(0).Selected = False
            chkRegister.Items(1).Selected = False
            chkRegister.Items(2).Selected = False
        Else
            chkRegister.Enabled = True
            chkNGO.Enabled = False
            chkNGO.Items(0).Selected = False
            chkNGO.Items(1).Selected = False
        End If
    End Sub

#End Region

    Private Function checkBeforeCompile() As Boolean
        Try
            Dim result As Boolean = True
            clsCheckLanguage = New clsCheckLanguage
            clsCheckID = New clsCheckID

            If txtBizNo.Text = "" Then
                result = False
                Image1.ImageUrl = "~/img/icon/cancel.png"
                strMsg = strMsg + Resources.resMsgAlertKYC.NotBizID + "\n"
            Else
                If Not txtBizNo.Text = hdfUniqueID.Value Then
                    If clsCheckID.checkUniqueID2(txtBizNo.Text, lblTypeKYC.Text, lblCustSEQ.Text) = False Then
                        result = False
                        Image1.ImageUrl = "~/img/icon/cancel.png"
                        clsCheckID = Nothing
                        strMsg = strMsg + Resources.resMsgAlertKYC.UniqueBizNo + "\n"
                    Else
                        Image1.ImageUrl = "~/img/icon/accept.png"
                    End If
                Else
                    Image1.ImageUrl = "~/img/icon/accept.png"
                End If

            End If

            If ddlBizType.SelectedIndex = 0 Then
                result = False
                Image2.ImageUrl = "~/img/icon/cancel.png"
                strMsg = strMsg + Resources.resMsgAlertKYC.NotBizType + "\n"
            ElseIf ddlBizType.SelectedValue = 2 Then
                'If Not txtBizNo.Text.Trim.Length = 13 Then
                '    result = False
                '    Image1.ImageUrl = "~/img/icon/cancel.png"
                '    strMsg = strMsg + Resources.resMsgAlertKYC.CheckBizNo + "\n"
                'Else
                '    Image2.ImageUrl = "~/img/icon/accept.png"
                'End If
                If Not (ddlBusiness1.SelectedValue > 51 And ddlBusiness1.SelectedValue < 60) And Not (ddlBusiness2.SelectedValue > 51 And ddlBusiness2.SelectedValue < 60) And Not (ddlBusiness3.SelectedValue > 51 And ddlBusiness3.SelectedValue < 60) Then
                    If Not txtBizNo.Text.Trim.Length = 13 Then
                        result = False
                        Image1.ImageUrl = "~/img/icon/cancel.png"
                        strMsg = strMsg + Resources.resMsgAlertKYC.CheckBizNo + "\n"
                    Else
                        Image2.ImageUrl = "~/img/icon/accept.png"
                    End If
                Else
                    Image2.ImageUrl = "~/img/icon/accept.png"
                End If
            Else
                Image2.ImageUrl = "~/img/icon/accept.png"
            End If

            If ddlPrefix.SelectedIndex = 0 Then
                result = False
                Image3.ImageUrl = "~/img/icon/cancel.png"
                strMsg = strMsg + Resources.resMsgAlertKYC.NotBizPrefix + "\n"
            Else
                Image3.ImageUrl = "~/img/icon/accept.png"
            End If

            If Not ddlNationality.SelectedIndex = 0 Then
                If ddlNationality.SelectedValue = 202 Then
                    If txtNameTH.Text = "" Then
                        result = False
                        Image4.ImageUrl = "~/img/icon/cancel.png"
                        strMsg = strMsg + Resources.resMsgAlertKYC.NotBizTHName + "\n"
                    Else
                        Image4.ImageUrl = "~/img/icon/accept.png"
                    End If
                End If
            End If

            If txtNameEN.Text = "" Then
                result = False
                Image5.ImageUrl = "~/img/icon/cancel.png"
                strMsg = strMsg + Resources.resMsgAlertKYC.NotBizENName + "\n"
            ElseIf clsCheckLanguage.checkLanguageEN(txtNameEN.Text.Trim) = False Then
                strMsg = strMsg + Resources.resMsgKYC.msgEN + "\n"
                result = False
                Image5.ImageUrl = "~/img/icon/cancel.png"
            Else
                Image5.ImageUrl = "~/img/icon/accept.png"
            End If

            If ddlNationality.SelectedIndex = 0 Then
                result = False
                Image6.ImageUrl = "~/img/icon/cancel.png"
                strMsg = strMsg + Resources.resMsgAlertKYC.NotNationality + "\n"
            Else
                Image6.ImageUrl = "~/img/icon/accept.png"
            End If

            If ddlBusiness1.SelectedIndex = 0 Then
                result = False
                Image7.ImageUrl = "~/img/icon/cancel.png"
                strMsg = strMsg + Resources.resMsgAlertKYC.NotBusiness + " 1" + "\n"
            ElseIf ddlBusiness1.SelectedValue = 99 And txtBizOther1.Text.Trim = "" Then
                result = False
                Image7.ImageUrl = "~/img/icon/cancel.png"
                strMsg = strMsg + Resources.resMsgAlertKYC.NotBusinessOther + " 1" + "\n"
            Else
                Image7.ImageUrl = "~/img/icon/accept.png"
            End If
            If Not ddlBusiness2.SelectedIndex = 0 Then
                If ddlBusiness2.SelectedValue = 99 And txtBizOther2.Text.Trim = "" Then
                    result = False
                    Image7.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotBusinessOther + " 2" + "\n"
                Else
                    Image7.ImageUrl = "~/img/icon/accept.png"
                End If
            End If
            If Not ddlBusiness3.SelectedIndex = 0 Then
                If ddlBusiness3.SelectedValue = 99 And txtBizOther3.Text.Trim = "" Then
                    result = False
                    Image7.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotBusinessOther + " 3" + "\n"
                Else
                    Image7.ImageUrl = "~/img/icon/accept.png"
                End If
            End If


            If ddlIncomeSource1.SelectedIndex = 0 Then
                result = False
                Image8.ImageUrl = "~/img/icon/cancel.png"
                strMsg = strMsg + Resources.resMsgAlertKYC.NotIncomeSource + "\n"
            Else
                Image8.ImageUrl = "~/img/icon/accept.png"
            End If

            If chkRegister.Enabled = True Then
                If Not chkRegister.Items(0).Selected = True And Not chkRegister.Items(1).Selected = True And Not chkRegister.Items(2).Selected = True Then
                    Image9.ImageUrl = "~/img/icon/accept.png"
                Else
                    If checkRegis() = True Then
                        Image9.ImageUrl = "~/img/icon/accept.png"
                    Else
                        result = False
                        Image9.ImageUrl = "~/img/icon/cancel.png"
                        strMsg = strMsg + Resources.resMsgKYC.msgRegis + "\n"
                    End If
                End If
            Else
                Image9.ImageUrl = "~/img/icon/accept.png"
            End If

            If chkNGO.Enabled = True Then
                If chkRegister.Items(0).Selected = True And chkRegister.Items(1).Selected = True Then
                    result = False
                    Image9.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgKYC.msgNGO + "\n"
                Else
                    Image9.ImageUrl = "~/img/icon/accept.png"
                End If
            Else
                Image9.ImageUrl = "~/img/icon/accept.png"
            End If

            statusValidation()

            clsCheckID = Nothing
            clsCheckLanguage = Nothing
            Return result
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Private Function checkRegis() As Boolean
        Try
            Dim result As Boolean = True
            If chkRegister.Items(0).Selected = True And chkRegister.Items(1).Selected = True Then
                result = False
            ElseIf chkRegister.Items(0).Selected = True And chkRegister.Items(2).Selected = True Then
                result = False
            ElseIf chkRegister.Items(1).Selected = True And chkRegister.Items(2).Selected = True Then
                result = False
            End If

            Return result
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Private Sub statusValidation()

        Image1.Visible = True
        Image2.Visible = True
        Image3.Visible = True
        Image4.Visible = True
        Image5.Visible = True
        Image6.Visible = True
        Image7.Visible = True
        Image8.Visible = True
        Image9.Visible = True

    End Sub

    Private Sub statusValidationFalse()

        Image1.Visible = False
        Image2.Visible = False
        Image3.Visible = False
        Image4.Visible = False
        Image5.Visible = False
        Image6.Visible = False

    End Sub

    Private Sub compileCDD()
        Try
            'btnSave.Visible = True
            btnReport.Visible = True

            Dim strReason = ""
            Dim risk As Integer

            risk = clsRiskLevel.riskLevel(txtBizNo.Text.Trim, txtNameTH.Text.Trim, "", "", txtNameEN.Text.Trim, "", "", 0, "", 0, "", 0, "", ddlBusiness1.SelectedValue, ddlBusiness1.SelectedItem.Text, ddlBusiness2.SelectedValue, ddlBusiness2.SelectedItem.Text, ddlBusiness3.SelectedValue, ddlBusiness3.SelectedItem.Text, ddlNationality.SelectedValue, ddlNationality.SelectedItem.Text, ddlIncomeSource1.SelectedValue, ddlIncomeSource1.SelectedItem.Text, ddlIncomeSource2.SelectedValue, ddlIncomeSource2.SelectedItem.Text, ddlIncomeSource3.SelectedValue, ddlIncomeSource3.SelectedItem.Text, strReason)

            If Not chkNGO.SelectedIndex = -1 Then
                risk = clsRiskLevel.checkNPO(risk, chkNGO.SelectedValue, strReason)
            End If
            If Not chkRegister.SelectedIndex = -1 Then
                risk = clsRiskLevel.checkRegister(risk, chkRegister.SelectedValue, strReason)
            End If

            If Not Session("Sanction") = Nothing Then
                risk = 3
                strReason = clsRiskLevel.sumString(strReason, Session("Sanction"))
                Session("Sanction") = Nothing
            End If

            If Not txtReasonSAS.Text = "" Then
                If hdfAML.Value > risk Then
                    risk = hdfAML.Value
                End If
            End If

            If risk = 1 Then
                txtRiskLevel.Text = "ลูกค้ามีความเสี่ยงระดับ 1"
                lblLevel.Text = 1
                txtReason.Text = ""
                txtRiskLevel.BackColor = Drawing.Color.LawnGreen
            ElseIf risk = 2 Then
                txtRiskLevel.Text = "ลูกค้ามีความเสี่ยงระดับ 2"
                lblLevel.Text = 2
                txtReason.Text = strReason
                txtRiskLevel.BackColor = Drawing.Color.Orange
            ElseIf risk = 3 Then
                txtRiskLevel.Text = "ลูกค้ามีความเสี่ยงระดับ 3"
                lblLevel.Text = 3
                txtReason.Text = strReason
                txtRiskLevel.BackColor = Drawing.Color.OrangeRed
            End If

            Session("strReason") = strReason

            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgKYC.msgLevel & risk & "')", True)

        Catch ex As Exception
            WriteError(ex, "compileCDD", "NonIndividualBoardNon")
            Throw ex
        End Try
    End Sub

    Private Function chkCardIdDuplicate(ByVal strUniqueID As String) As Boolean
        Try
            Dim blnDup As Boolean = True

            Dim qryDup = (From tblDup In ds.Tables("dsCustomerCom") Where tblDup.Item("UNIQUEID") = strUniqueID).ToList

            If Not (qryDup.Count = 0) Then
                blnDup = False
            End If

            'If (strUniqueID.Trim = txtUniqueID.Text.Trim) Then
            '    blnDup = False
            'End If

            qryDup = Nothing

            Return blnDup
        Catch ex As Exception
            WriteError(ex, "chkCardIdDuplicate", "NonIndividualBoardNon")
            Throw ex
        End Try
    End Function

    Sub saveData()
        Try
            Dim drCust As DataRow = ds.Tables("dsCustomerCom").NewRow
            If lblCustSEQ.Text = 0 Then
                drCust("CustSEQ") = Now.Millisecond + Now.Minute + Now.Second
                drCust("CreateBy") = "AutoGenPK"
            Else
                drCust("CustSEQ") = lblCustSEQ.Text
                drCust("CreateBy") = " "
            End If

            drCust("CustType") = 2
            drCust("CustSubType") = ddlBizType.SelectedValue
            drCust("AMLCDD") = CInt(lblLevel.Text.Trim)
            drCust("AMLREASON") = CStr(txtReason.Text.Trim)
            drCust("AMLCDDOVERVIEW") = CInt(lblLevel.Text.Trim)
            drCust("AMLREASONOVERVIEW") = CStr(txtReason.Text.Trim)
            drCust("UNIQUEID") = txtBizNo.Text.Trim
            drCust("ThPreFix") = ddlPrefix.SelectedValue
            drCust("ThFirstName") = txtNameTH.Text.Trim
            drCust("EnFirstName") = txtNameEN.Text.Trim
            If Not ddlBusiness1.SelectedIndex = 0 Then
                drCust("BIZTYPE1") = ddlBusiness1.SelectedValue
                drCust("BIZTYPEOTHER1") = txtBizOther1.Text.Trim
            Else
                drCust("BIZTYPE1") = DBNull.Value
                drCust("BIZTYPEOTHER1") = ""
            End If
            If Not ddlBusiness2.SelectedIndex = 0 Then
                drCust("BIZTYPE2") = ddlBusiness2.SelectedValue
                drCust("BIZTYPEOTHER2") = txtBizOther2.Text.Trim
            Else
                drCust("BIZTYPE2") = DBNull.Value
                drCust("BIZTYPEOTHER2") = ""
            End If
            If Not ddlBusiness3.SelectedIndex = 0 Then
                drCust("BIZTYPE3") = ddlBusiness3.SelectedValue
                drCust("BIZTYPEOTHER3") = txtBizOther3.Text.Trim
            Else
                drCust("BIZTYPE3") = DBNull.Value
                drCust("BIZTYPEOTHER3") = ""
            End If

            drCust("BIZDESC1") = txtDes1.Text.Trim
            drCust("BIZDESC2") = txtDes2.Text.Trim
            drCust("BIZDESC3") = txtDes3.Text.Trim

            drCust("Nationality") = ddlNationality.SelectedValue
            drCust("IncomeSource1") = ddlIncomeSource1.SelectedValue
            If Not ddlIncomeSource2.SelectedIndex = 0 Then
                drCust("IncomeSource2") = ddlIncomeSource2.SelectedValue
            End If
            If Not ddlIncomeSource3.SelectedIndex = 0 Then
                drCust("IncomeSource3") = ddlIncomeSource3.SelectedValue
            End If

            If Not chkNGO.SelectedIndex = -1 Then
                drCust("NGOCHECK1") = chkNGO.SelectedValue
            End If
            If Not chkRegister.SelectedIndex = -1 Then
                drCust("COMPCHECK1") = chkRegister.SelectedValue
            End If

            drCust("POCODE") = ddlPosition.SelectedValue
            drCust("PONAME") = ddlPosition.SelectedItem.Text
            'drCust("ETL_STATUS") = "N"
            ds.Tables("dsCustomerCom").Rows.Add(drCust)
        Catch ex As Exception
            WriteError(ex, "savedata", "NonIndividualBoardNon")
            Throw ex
        End Try
    End Sub

    Sub updateData()
        Try
            ds.Tables("dsCustomerCom").Rows(index)("AMLCDD") = CInt(lblLevel.Text.Trim)
            ds.Tables("dsCustomerCom").Rows(index)("AMLREASON") = CStr(txtReason.Text.Trim)
            'If ds.Tables("dsCustomerCom").Rows(index)("AMLCDDOVERVIEW") > CInt(lblLevel.Text.Trim) Then
            ds.Tables("dsCustomerCom").Rows(index)("AMLCDDOVERVIEW") = CInt(lblLevel.Text.Trim)
            ds.Tables("dsCustomerCom").Rows(index)("AMLREASONOVERVIEW") = CStr(txtReason.Text.Trim)
            'End If

            ds.Tables("dsCustomerCom").Rows(index)("UNIQUEID") = txtBizNo.Text.Trim
            ds.Tables("dsCustomerCom").Rows(index)("ThPreFix") = ddlPrefix.SelectedValue
            ds.Tables("dsCustomerCom").Rows(index)("ThFirstName") = txtNameTH.Text.Trim
            ds.Tables("dsCustomerCom").Rows(index)("EnFirstName") = txtNameEN.Text.Trim

            If Not ddlBusiness1.SelectedIndex = 0 Then
                ds.Tables("dsCustomerCom").Rows(index)("BIZTYPE1") = ddlBusiness1.SelectedValue
                ds.Tables("dsCustomerCom").Rows(index)("BIZTYPEOTHER1") = txtBizOther1.Text.Trim
            Else
                ds.Tables("dsCustomerCom").Rows(index)("BIZTYPE1") = DBNull.Value
                ds.Tables("dsCustomerCom").Rows(index)("BIZTYPEOTHER1") = ""
            End If
            If Not ddlBusiness2.SelectedIndex = 0 Then
                ds.Tables("dsCustomerCom").Rows(index)("BIZTYPE2") = ddlBusiness2.SelectedValue
                ds.Tables("dsCustomerCom").Rows(index)("BIZTYPEOTHER2") = txtBizOther2.Text.Trim
            Else
                ds.Tables("dsCustomerCom").Rows(index)("BIZTYPE2") = DBNull.Value
                ds.Tables("dsCustomerCom").Rows(index)("BIZTYPEOTHER2") = ""
            End If
            If Not ddlBusiness3.SelectedIndex = 0 Then
                ds.Tables("dsCustomerCom").Rows(index)("BIZTYPE3") = ddlBusiness3.SelectedValue
                ds.Tables("dsCustomerCom").Rows(index)("BIZTYPEOTHER3") = txtBizOther3.Text.Trim
            Else
                ds.Tables("dsCustomerCom").Rows(index)("BIZTYPE3") = DBNull.Value
                ds.Tables("dsCustomerCom").Rows(index)("BIZTYPEOTHER3") = ""
            End If

            ds.Tables("dsCustomerCom").Rows(index)("BIZDESC1") = txtDes1.Text.Trim
            ds.Tables("dsCustomerCom").Rows(index)("BIZDESC2") = txtDes2.Text.Trim
            ds.Tables("dsCustomerCom").Rows(index)("BIZDESC3") = txtDes3.Text.Trim

            ds.Tables("dsCustomerCom").Rows(index)("Nationality") = ddlNationality.SelectedValue
            ds.Tables("dsCustomerCom").Rows(index)("IncomeSource1") = ddlIncomeSource1.SelectedValue
            If Not ddlIncomeSource2.SelectedIndex = 0 Then
                ds.Tables("dsCustomerCom").Rows(index)("IncomeSource2") = ddlIncomeSource2.SelectedValue
            Else
                ds.Tables("dsCustomerCom").Rows(index)("IncomeSource2") = DBNull.Value
            End If
            If Not ddlIncomeSource3.SelectedIndex = 0 Then
                ds.Tables("dsCustomerCom").Rows(index)("IncomeSource3") = ddlIncomeSource3.SelectedValue
            Else
                ds.Tables("dsCustomerCom").Rows(index)("IncomeSource3") = DBNull.Value
            End If

            If Not chkNGO.SelectedIndex = -1 Then
                ds.Tables("dsCustomerCom").Rows(index)("NGOCHECK1") = chkNGO.SelectedValue
                ds.Tables("dsCustomerCom").Rows(index)("COMPCHECK1") = DBNull.Value
            End If
            If Not chkRegister.SelectedIndex = -1 Then
                ds.Tables("dsCustomerCom").Rows(index)("COMPCHECK1") = chkRegister.SelectedValue
                ds.Tables("dsCustomerCom").Rows(index)("NGOCHECK1") = DBNull.Value
            End If

            ds.Tables("dsCustomerCom").Rows(index)("POCODE") = ddlPosition.SelectedValue
            ds.Tables("dsCustomerCom").Rows(index)("PONAME") = ddlPosition.SelectedItem.Text
            'ds.Tables("dsCustomerCom").Rows(index)("ETL_STATUS") = "N"
            ds.Tables("dsCustomerCom").Rows(index).AcceptChanges()
        Catch ex As Exception
            WriteError(ex, "updatedata", "NonIndividualBoardNon")
            Throw ex
        End Try
    End Sub

    Private Sub SaveLogPrint(ByVal index As Integer)
        Try
            Dim program As String = ""
            If CInt(Session("KYC")) = 1 Then
                program = "M12"
            ElseIf CInt(Session("KYC")) = 2 Then
                program = "M22"
            ElseIf CInt(Session("KYC")) = 3 Then
                program = "M32"
            Else
                program = "M42"
            End If

            Dim desc As String = ""
            If index = 1 Then
                desc = "พิมพ์ฟอร์ม KYC"
            Else
                desc = "พิมพ์ผลประเมินความเสี่ยง (ผู้ถือหุ้น)"
            End If

            Dim clsLogTransaction As New clsLogTransaction
            clsLogTransaction.saveLogTransaction(txtBizNo.Text.Trim, clsSessionMenuRight.getUserName, 2, desc, program)
            clsLogTransaction = Nothing
        Catch ex As Exception
            WriteError(ex, "SaveLogPrint", "NonIndividualBoardNon")
            Throw ex
        End Try
    End Sub

#End Region

    Protected Sub btnEditCompile_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEditCompile.Click
        If (Panel2.Enabled = False) Then
            Panel2.Enabled = True
            btnCompile.Visible = True
            btnEditCompile.Visible = False
            btnReport.Visible = False
        Else
            Panel2.Enabled = False
            btnCompile.Visible = False
            btnEditCompile.Visible = True
            btnReport.Visible = True
        End If
    End Sub
End Class
